#include <iostream>
#include <condition_variable>
#include <thread>
#include <atomic>

std::mutex mutex_;
std::condition_variable cv_;

std::atomic<bool> ready_ { false };

void _thrd_waiting() {
    std::cout << "[ WAIT ] Waiting >>> " << std::endl;

    std::unique_lock<std::mutex> lock(mutex_);
    cv_.wait(lock, []{ return ready_.load(); });

    std::cout << "[ WAIT ] Got signal! " << std::endl;
}


void _thrd_setting() {
    std::cout << "[ SET  ] Preparing >>> " << std::endl;

    ready_ = true;
    cv_.notify_one();

    std::cout << "[ SET  ] Prepare finished. >>> " << std::endl;
}


int main(int argc, char **argv) {
    int ret = 0;

    std::thread th_w(_thrd_waiting);
    std::thread th_s(_thrd_setting);

    th_w.join();
    th_s.join();

    return ret;
}
